package com.travel.controller;

import com.qianfeng.util.ResultMsg;
import com.travel.entity.TbStrstegy;
import com.travel.entity.TbView;
import com.travel.service.StrstegyService;
import com.travel.utils.QiNiuTools;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/Strstegy")
@Api(value = "攻略相关的业务",description = "攻略")
public class FontStrstegyController {


    @Autowired
    StrstegyService strstegyService;

    @Autowired
    QiNiuTools qiNiuTools;

    //分页查询所有的攻略
    @GetMapping("/strstegyGetdAll")
    public ResultMsg strstegyGetdAll(@RequestParam(required = false,defaultValue = "1") int current, @RequestParam(required = false,defaultValue = "1") int size){
        return strstegyService.strstegyGetAll(current,size);
    }
    @GetMapping("/strstegySeleteAll")
    public ResultMsg strstegySeleteAll(){
        return strstegyService.strstegySeleteAll();
    }

    //根据攻略Id查寻一条攻略
    @GetMapping("/strstegyGetOne")
    public ResultMsg strstegyGetOne(Integer strstegyId){
        return strstegyService.strstegyGetOne(strstegyId);
    }

    //根据用户Id查询该用户的攻略
    @GetMapping("/strstegyGetUserId")
    public ResultMsg strstegyGetUserId(Integer userId){
        return strstegyService.strstegyGetUserId(userId);
    }

    //根据景点查询一个攻略
    @GetMapping("/strstegyView")
    public ResultMsg strstegyView(Integer viewId){
        return strstegyService.strstegyView(viewId);
    }
    //根据景点查询一个攻略
    @GetMapping("/strstegyViewName")
    public ResultMsg strstegyView(TbView tbView){
        return strstegyService.strstegyViewName(tbView);
    }

    //上传一个攻略
    @PostMapping("/AddOne")
    public ResultMsg strstegyAddOne(@RequestBody TbStrstegy tbStrstegy){
        return strstegyService.strstegyAddOne(tbStrstegy);
    }

    //图片上传
    @PostMapping("/upload")
    public ResultMsg upload(MultipartFile file, HttpServletRequest request){
        String url = qiNiuTools.upload(file);
        return ResultMsg.success(url);
    }
}
